package com.yupi.maker.generator;

import java.io.*;

/**
 * @version 1.0
 * @Author moresuo
 * @Date 2024/9/10 18:32
 * @注释 自动生成jar包
 */
public class JarGenerator {
    public static void doGenerator(String projectDir) throws IOException, InterruptedException {
        //调用Process类执行Maven打包命令
        //不同的操作系统执行的命令不一样
        String winMavenCommand="mvn.cmd clean package -DskipTests=true";//先清理在打包，打包的过程中跳过测试
        String otherMavenCommand="mvn clean package -DskipTests=true";
        String mavenCommand=winMavenCommand;

        ProcessBuilder processBuilder = new ProcessBuilder(mavenCommand.split(" "));//按照空格进行拆分
        processBuilder.directory(new File(projectDir));//设置工作目录

        Process process = processBuilder.start();

        //读取命令的输出
        InputStream inputStream = process.getInputStream();
        BufferedReader reader=new BufferedReader(new InputStreamReader(inputStream));
        String line;
        while((line=reader.readLine())!=null){
            System.out.println(line);
        }

        //等待命令执行完成
        int exitCode = process.waitFor();
        System.out.println("命令执行完成，退出码："+exitCode);
    }
}
